package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ：zfr
 * @date ：2021/12/30 16:18
 */
public class XiaoyuCostumeItemRecycleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        List<ActivityInfo> activityInfoList = NormalActivityMgr.getXiaoyuCostumeActivityInfoList();
        if (activityInfoList != null) {
            for (ActivityInfo activityInfo : activityInfoList) {
                int itemId = Integer.parseInt(activityInfo.getParam4().split(";")[0]);
                long recycleTime = activityInfo.getEndShowTime() * 1000L + 10 * 60 * 1000;
                Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(activityInfo.getActivityId());
                if (activityConfigMap != null && activityConfigMap.containsKey("EXCHANGE_SCORE_ITEM_ID")) {
                    List<String> paramList = new ArrayList<>();
                    paramList.add(String.valueOf(itemId));
                    paramList.add(activityConfigMap.get("EXCHANGE_SCORE_ITEM_ID").getValue());
                    paramList.add("3");
                    paramList.add(activityInfo.getActivityName());
                    ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, 1, recycleTime, paramList);
                } else {
                    ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, recycleTime);
                }
            }
        }
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.XiaoyuCostumeActivity.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if (data.getRecycleType() == 0) {
            int itemId = data.getItemId();
            UserBagItem userBagItem = getUserBagItem(userId, itemId);
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        } else if (data.getRecycleType() == 1) {
            item2Score(userId, data);
        }
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
